package com.zmn.mcc.services.impl.staff;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.mcc.model.dto.dpermit.DpermitCountDO;
import com.zmn.mcc.common.dto.permit.DpermitLitDO;
import com.zmn.mcc.model.entity.staff.McStaffDpermit;
import com.zmn.mcc.model.entity.staff.McStaffDpermitQuery;
import com.zmn.mcc.persistence.interfaces.staff.StaffDpermitDao;
import com.zmn.mcc.services.interfaces.staff.StaffDpermitService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author heguanghua
 * @since 2020/04/14 18:29
 */
@Service
public class StaffDpermitServiceImpl implements StaffDpermitService {

    @Resource
    private StaffDpermitDao staffDpermitDao;


    @Override
    public McStaffDpermit findByKey(Integer staffId, Integer dataType, Integer dataLevel, Integer dataId) {
        McStaffDpermit staffDpermit = new McStaffDpermit();
        staffDpermit.setStaffId(staffId);
        staffDpermit.setDataType(dataType);
        staffDpermit.setDataLevel(dataLevel);
        staffDpermit.setDataId(dataId);
        return this.findByKey(staffDpermit);
    }
    @Override
    public McStaffDpermit findByKey(McStaffDpermit staffDpermit) {
        return staffDpermitDao.findByKey(staffDpermit);
    }

    @Override
    public McStaffDpermit findByQuery(McStaffDpermitQuery query) {
        return staffDpermitDao.findByQuery(query);
    }

    @Override
    public List<McStaffDpermit> listPageByQuery(McStaffDpermitQuery query) {
        Integer count = this.countByQuery(query);
        query.setTotalCount(count);
        return count == 0 ? new ArrayList<>(0) : staffDpermitDao.listPageByQuery(query);
    }

    @Override
    public List<McStaffDpermit> listByStaffId(Integer staffId) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        return this.listByQuery(query);
    }
    @Override
    public List<McStaffDpermit> listByStaffIdAndDataType(Integer staffId, Integer dataType) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        query.setDataType(dataType);
        return this.listByQuery(query);
    }
    @Override
    public List<McStaffDpermit> listByStaffIdAndDataAttr(Integer staffId, Integer dataType, Integer dataLevel) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        query.setDataType(dataType);
        query.setDataLevel(dataLevel);
        return this.listByQuery(query);
    }
    @Override
    public List<McStaffDpermit> listByStaffIdAndDataAttr(Integer staffId, Integer dataType, List<Integer> dataLevels) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        query.setDataType(dataType);
        query.setDataLevels(dataLevels);
        return this.listByQuery(query);
    }

    @Override
    public List<McStaffDpermit> listByQuery(McStaffDpermitQuery query) {
        return staffDpermitDao.listByQuery(query);
    }

    @Override
    public List<Integer> listDataIdByStaffIdAndDataType(Integer staffId, Integer dataType) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        query.setDataType(dataType);
        return this.listDataIdByQuery(query);
    }
    @Override
    public List<Integer> listDataIdByStaffIdAndDataAttr(Integer staffId, Integer dataType, Integer dataLevel) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        query.setDataType(dataType);
        query.setDataLevel(dataLevel);
        return this.listDataIdByQuery(query);
    }
    @Override
    public List<Integer> listDataIdByStaffIdAndDataAttr(Integer staffId, Integer dataType, List<Integer> dataLevels) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        query.setDataType(dataType);
        query.setDataLevels(dataLevels);
        return this.listDataIdByQuery(query);
    }
    @Override
    public List<Integer> listDataIdByQuery(McStaffDpermitQuery query) {
        return staffDpermitDao.listDataIdByQuery(query);
    }

    @Override
    public List<DpermitLitDO> listDpermitLitByStaffIdAndDataType(Integer staffId, Integer dataType) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        query.setDataType(dataType);
        return this.listDpermitLitByQuery(query);
    }
    @Override
    public List<DpermitLitDO> listDpermitLitByQuery(McStaffDpermitQuery query) {
        return staffDpermitDao.listDpermitLitByQuery(query);
    }

    @Override
    public Integer countByQuery(McStaffDpermitQuery query) {
        return staffDpermitDao.countByQuery(query);
    }

    @Override
    public List<DpermitCountDO> countByQueryGroupByParentId(McStaffDpermitQuery query) {
        return staffDpermitDao.countByQueryGroupByParentId(query);
    }



    @Override
    public Integer updateByKey(McStaffDpermit staffDpermit) {
        return staffDpermitDao.updateByKey(staffDpermit);
    }

    @Override
    public Integer updateSubAllByQuery(McStaffDpermitQuery query) {
        return staffDpermitDao.updateSubAllByQuery(query);
    }



    @Override
    public Integer insert(McStaffDpermit staffDpermit) {
        if(staffDpermit.getCreateTime() == null) {
            staffDpermit.setCreateTime(DateUtil.getNow());
        }
        return staffDpermitDao.insert(staffDpermit);
    }

    @Override
    public Integer insertByBatch(List<McStaffDpermit> staffDpermits) {
        return staffDpermitDao.insertByBatch(staffDpermits);
    }



    @Override
    public Integer deleteByKey(Integer staffId, Integer dataType, Integer dataLevel, Integer dataId) {
        McStaffDpermit staffDpermit = new McStaffDpermit();
        staffDpermit.setStaffId(staffId);
        staffDpermit.setDataType(dataType);
        staffDpermit.setDataLevel(dataLevel);
        staffDpermit.setDataId(dataId);
        return this.deleteByKey(staffDpermit);
    }
    @Override
    public Integer deleteByKey(McStaffDpermit staffDpermit) {
        return staffDpermitDao.deleteByKey(staffDpermit);
    }

    @Override
    public Integer deleteByStaffId(Integer staffId) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        return this.deleteByQuery(query);
    }
    @Override
    public Integer deleteByStaffIdAndDataType(Integer staffId, Integer dataType) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        query.setDataType(dataType);
        return this.deleteByQuery(query);
    }
    @Override
    public Integer deleteByStaffIdAndDataAttr(Integer staffId, Integer dataType, List<Integer> dataLevels) {
        McStaffDpermitQuery query = new McStaffDpermitQuery();
        query.setStaffId(staffId);
        query.setDataType(dataType);
        query.setDataLevels(dataLevels);
        return this.deleteByQuery(query);
    }

    @Override
    public Integer deleteByQuery(McStaffDpermitQuery query) {
        return staffDpermitDao.deleteByQuery(query);
    }
}
